package com.iplay.service.notification.type.order.type;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

import com.iplay.component.im.OutgoingMessage;
import com.iplay.service.notification.type.order.OrderMessage;
import com.iplay.service.notification.type.order.OrderMessageEntity;
import com.iplay.service.notification.type.order.OrderOutgoingMessage;
import com.iplay.service.order.RoleInOrder;
import com.iplay.service.user.UserContrains;

public abstract class OrderMessageType {
	private OrderMessageEntity entity;

	public OrderMessageType(OrderMessageEntity entity) {
		this.entity = entity;
	}

	public OrderMessageEntity getEntity() {
		return entity;
	}

	public abstract List<OutgoingMessage> getOutgoingMessage();

	protected List<OutgoingMessage> getDefaultOutgoingMessageForManagerAndAdmin(String messageForManager,
			String messageForAdmin) {
		OrderMessageEntity entity = this.getEntity();
		List<OutgoingMessage> messages = new LinkedList<>();
		if (!Objects.equals(entity.getCustomer(), entity.getManager()))
			messages.add(new OrderOutgoingMessage(entity.getManager(), new OrderMessage(entity.getOrderId(),
					RoleInOrder.MANAGER, entity.getOrderStatusCategory(), String.format(messageForManager, entity.getCustomer(), entity.getHotel()))));
		messages.add(new OrderOutgoingMessage(UserContrains.SUPER_ADMIN_USERNAME, new OrderMessage(entity.getOrderId(),
				String.format(messageForAdmin, entity.getCustomer(), entity.getHotel()))));
		return messages;
	}

	protected List<OutgoingMessage> getStatusUpdatedMessageForCustomerAndManager(String messageForCustomer,
			String messageForManager) {
		OrderMessageEntity entity = this.getEntity();
		List<OutgoingMessage> messages = new LinkedList<>();
		messages.add(new OrderOutgoingMessage(entity.getCustomer(), new OrderMessage(entity.getOrderId(),
				RoleInOrder.CUSTOMER, entity.getOrderStatusCategory(), String.format(messageForCustomer, entity.getHotel()))));
		if (!Objects.equals(entity.getCustomer(), entity.getManager()))
			messages.add(new OrderOutgoingMessage(entity.getManager(), new OrderMessage(entity.getOrderId(),
					RoleInOrder.MANAGER, entity.getOrderStatusCategory(), String.format(messageForManager, entity.getCustomer(), entity.getHotel()))));
		return messages;
	}
}
